home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4908 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.5 KB

  1. Path: news.halcyon.com!usenet
  2. From: normanb@halcyon.com (Norm Bryar)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Why Do I Use An Ampersand in Member Class Parameters?
  5. Date: Thu, 01 Feb 1996 16:07:08 GMT
  6. Organization: Northwest Nexus Inc.
  7. Message-ID: <4eqoee$bi5@news.halcyon.com>
  8. References: <4emnv2$n5o@alcor.usc.edu> <4empsa$18b@ixnews5.ix.netcom.com>
  9. NNTP-Posting-Host: blv-pm2-ip25.halcyon.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. judgemi@ix.netcom.com (Michael Judge ) wrote:
  13.  
  14. >In <4emnv2$n5o@alcor.usc.edu> wawda@alcor.usc.edu (Abu Wawda) writes: 
  15. >>
  16. >>class Simple
  17. >>{
  18. >>public:
  19. >>  Simple();
  20. >>  int operator += (const Simple &);
  21. >>private:
  22. >>  int data;
  23. >>};
  24. >>
  25. >>I have seen many examples of this but I what I don't understand is why
  26. >>there is an amersand after Simple? ...
  27. >>
  28. >>-Abu Wawda
  29. >> wawda@scf.usc.edu
  30. >>
  31. >>
  32.  
  33. >I am not sure i understand this, but the & makes the parameter a
  34. >reference. That way a copy of simple is not made when the method is
  35. >used. Use & insted of * because you are more assured that the parameter
  36. >is a legal object. (unless someone did some evil casting)
  37.  
  38. >note: i dont have my compiler with me but i dont think one simple
  39. >object can necessarily access another's private members without an
  40. >access method...If i am mistaken someone please correct me.
  41.  
  42. It's fine for any Simple instance to access private data from any
  43. Simple instance passed in.  Derivatives of Simple may not access
  44. private data of Simple, except by calling Simple methods explicitly.
  45.  
  46.                     --Norm
  47.  
  48.